<html>
<head>
	<link rel="stylesheet" type="text/css" href="css/style.css"/>
</head>
<?php
  require_once 'header.php';

  $ConnectDB = new connectDB();
  $SQLList = new sqlList();

  $idPoem = "";
  if(isset($_POST["sid"]))
  {
    $idPoem = $_POST["sid"];
  }
  else
  {
    if(isset($_GET["sid"]))
    {
      $idPoem = $_GET["sid"];
    }
  }

  /* Song informaton */
  $result = $ConnectDB->buildPreparedStatments($SQLList->SelectSongDetail);
  $result->bind_param( 'i', $idPoem );
  $result->execute();
  $result->bind_result($idPoem, $title, $content, $music, $lyrics, $youtubeCode, $album);
  $resultCnt = $result->fetch();
  $result->close();
  $pattern = '/\n/i';
  $replacement = '<br/>';
  $content = preg_replace($pattern, $replacement, $content);
  /* Song informaton [End] */

  /* Categroy Information */
  $resultCat = $ConnectDB->buildPreparedStatments($SQLList->SelectSongCategory);
  $resultCat->bind_param( 'i', $idPoem );
  $resultCat->execute();
  $resultCat->bind_result($categoryId, $categoryName);
  $index = 0;
  while ($rowSet = $resultCat->fetch())
	{
	  $categoryIdArr[$index] = $categoryId;
	  $categoryArr[$index] = $categoryName;
	  $index++;
	}
	$resultCat->close();
	/* Song informaton [End] */
?>
<body>
<div class="contain">
<div class="youtubeContain">
  <iframe width="500px" height="350px" src="http://www.youtube.com/embed/<?php print $youtubeCode;?>" frameborder="0" allowfullscreen>
  </iframe>
</div>
<div class="infoContain">
	<?php
	print "<div>分類：";
	if(count($categoryArr)>0)
	{
  	for ($i=0; $i < count($categoryArr); $i++)
  	{
  	  print '<a href="category.php?cid=' . $categoryIdArr[$i] . '&ctitle=' . $categoryArr[$i] . '">';
      print "$categoryArr[$i]";
      print '</a>, ';
    }
	}
	else
	{
    print "未有分類";
	}
  print "</div>\n";

  if ($resultCnt > 0 )
	{
	   print "<div>歌名: $title</div>\n";
	   print "<div>專輯 : $album</div><br/>\n";
	   print "<div>作曲: $music</div>\n";
	   print "<div>作詞 : $lyrics</div><br/>\n";
	   print "<div>歌詞: <br/>$content</div>\n";
	   //print "<div>YoutubeCode: $youtubeCode</div>\n";
	}
	?>
</div>
</div>
</body>
</html>